﻿using System.Collections.Generic;
using System.Linq;

using VirtualTournaments.DataAccess.EntityManagers;
using VirtualTournaments.DataAccess.SqlServer.DataMappers;

namespace VirtualTournaments.DataAccess.SqlServer.EntityManagers
{
	internal sealed class TeamsManager : ITeamsManager
	{
		#region Singleton implementation

		private static TeamsManager _instance = null;
		private static readonly object _instanceLocker = new object();

		private TeamsManager() { }

		public static TeamsManager Instance
		{
			get
			{
				if (_instance == null)
				{
					lock (_instanceLocker)
					{
						if (_instance == null)
						{
							_instance = new TeamsManager();
						}
					}
				}
				return _instance;
			}
		}

		#endregion

		#region ITeamsManager Members

		public IEnumerable<Business.Tournaments.Team> GetByTournament(Business.Tournaments.Tournament tournament)
		{
			return TeamsDataMapper.Instance.GetList(team => team.TournamentTeams.Count(tournamentTeam => tournamentTeam.Tournament.Name.ToLower() == tournament.Name.ToLower()) == 1).AsEnumerable();
		}

		public Business.Tournaments.Team GetByName(string teamName)
		{
			return TeamsDataMapper.Instance.GetOneAsBusinessObject(team => team.Name.ToLower() == teamName.ToLower());
		}

		#endregion

		#region IEntityManager<Team> Members

		public IEnumerable<Business.Tournaments.Team> GetAll()
		{
			throw new System.NotImplementedException();
		}

		public void Save(Business.Tournaments.Team entity)
		{
			throw new System.NotImplementedException();
		}

		public void Delete(Business.Tournaments.Team entity)
		{
			throw new System.NotImplementedException();
		}

		#endregion
	}
}
